define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            $.fn.bootstrapTable.locales[Table.defaults.locale]['formatSearch'] = function(){return "搜索主体";};
            Table.api.init({
                extend: {
                    index_url: 'balance/index' + location.search,
                    // add_url: 'balance/add',
                    // edit_url: 'balance/edit',
                    // del_url: 'balance/del',
                    multi_url: 'balance/multi',
                    import_url: 'balance/import',
                    table: 'balance',
                }
            });

            var table = $("#table");

            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                var extend = data.extend;
                var html = [];
                for (var i = 0; i < extend.length; i++) {
                    html.push(extend[i]["name"] + ":<span>【"+extend[i]["value"]+"】</span>");
                }
                $(".extend").html(html.join(""));
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'main_type', title: __('Main_type'), searchList: {"1":__('机构'),"2":__('代理')},formatter: function (value) {
                            return value == 1 ? "机构" : "代理";
                            }},
                        {field: 'info', title: __('Main_id'),operate: false},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'total', title: __('Total'), operate:'BETWEEN'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
